<template>
  <div class="goods-tabs">
    <nav>
      <a :class="{
        active: activeName === 'GoodsDetail'
      }" href="javascript:;" @click="clickTab('GoodsDetail')">商品详情</a>
      <a href="javascript:;" :class="{ active: activeName === 'GoodsComment' }"
        @click="clickTab('GoodsComment')">商品评价<span>({{ goods.commentCount
        }})</span></a>
    </nav>
    <!-- 切换内容的地方 -->
    <!-- 这个位置显示对应的组件 GoodsDetail 或者 GoodsComment -->
    <KeepAlive>
      <component :is="CurrentCompoent[activeName]"></component>
    </KeepAlive>
  </div>

</template>
<script lang="ts" setup >
import { ref, reactive, defineAsyncComponent, markRaw, inject } from 'vue'
const CurrentCompoent = reactive({
  GoodsDetail: markRaw(defineAsyncComponent(() => import('./goods-detail.vue'))),
  GoodsComment: markRaw(defineAsyncComponent(() => import('./goods-comment.vue')))
})
const activeName = ref('GoodsDetail')
const clickTab = (name) => {
  activeName.value = name
}
const goods: any = inject('goods')
</script>
<style lang="less" scoped>
@import '../../assets/styles/mixins.less';
@import '../../assets/styles/variables.less';

.goods-tabs {
  min-height: 600px;
  background: #fff;

  nav {
    height: 70px;
    line-height: 70px;
    display: flex;
    border-bottom: 1px solid #f5f5f5;

    a {
      padding: 0 40px;
      font-size: 18px;
      position: relative;

      >span {
        color: @priceColor;
        font-size: 16px;
        margin-left: 10px;
      }

      &:first-child {
        border-right: 1px solid #f5f5f5;
      }

      &.active {
        &::before {
          content: "";
          position: absolute;
          left: 40px;
          bottom: -1px;
          width: 72px;
          height: 2px;
          background: @xtxColor;
        }
      }
    }
  }
}
</style>